package org.sy.lab.Java7并发编程实战.四线程执行器.三在执行器中执行任务并返回结果;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class FactorialCalculator implements Callable<Integer>{
	private Integer number;
	public FactorialCalculator(Integer number) {
		this.number = number;
	}
	@Override
	public Integer call() throws Exception {
		int result = 1;
		if((number == 0) || number == 1) {
			result = 1;
		} else {
			for(int i=2; i<number; i++) {
				result *= i;
				TimeUnit.MILLISECONDS.sleep(20);
			}
		}
		System.out.printf("%s: %d\n", Thread.currentThread().getName(), result);
		return result;
	}
}
